let express = require('express');
let router = express.Router();
let con =require("../model/db")
/* GET users listing. */
router.get('/select/:id', function(req, res, next) {
  const {id}=req.params;
  con.query("SELECT * FROM `profile` WHERE id=?",id,(err,result)=>{
    if (err) throw err;
    res.json({
      code:200,
      msg:"数据获取成功",
      data:result[0]
    })
  })
});
router.get('/show',function (req, res) {
  res.render('profile');
})
router.put('/update/:id',function(req,res,next){
  const {id}=req.params;
  const {body}=req;
  con.query("UPDATE `profile` SET name=?,age=?,avatar=? WHERE id=?",[body.name,body.age,body.avatar,id],(err,result)=>{
    if (err) throw err;
    if (result.affectedRows == 1) {
      return res.status(200).json({ code: 200, msg: '更新成功' });
    } else {
      return res.status(500).json({ code: 500, msg: '更新失败' });
    }
  })
})
module.exports = router;
